package com.hzlj.position.locate.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fz.common.base.converter.QueryWrapperConverterPlus;
import com.fz.common.base.converter.RemoveWrapperPlus;
import com.fz.common.base.dto.DeleteCommonDTO;
import com.fz.common.base.dto.PageParamDTO;
import com.fz.common.base.dto.QueryPageResultDTO;
import com.fz.common.base.dto.SortParamDTO;
import com.hzlj.position.locate.common.dto.reportInitiativeSetting.ReportInitiativeSettingQueryParamDTO;
import com.hzlj.position.locate.common.dto.reportInitiativeSetting.ReportInitiativeSettingQueryResultDTO;
import com.hzlj.position.locate.common.model.ReportInitiativeSetting;
import com.hzlj.position.locate.mapper.ReportInitiativeSettingMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 通信联络核查-人脸签到-配置表(ReportInitiativeSetting)表操作类
 *
 * @author lifh
 * @date 2023-07-20 10:41:38
 */
@Repository
public class ReportInitiativeSettingDao extends ServiceImpl<ReportInitiativeSettingMapper, ReportInitiativeSetting> {
    @Resource
    private ReportInitiativeSettingMapper reportInitiativeSettingMapper;

    /**
     * 删除数据
     *
     * @param dto 实例对象
     * @return 是否成功
     */
    public boolean deleteReportInitiativeSetting(DeleteCommonDTO<String> dto) {
        return RemoveWrapperPlus.remove(this, dto);
    }

    /**
     * 查询列表：不分页
     *
     * @param dto 查询条件
     * @return 对象列表
     */
    public List<ReportInitiativeSettingQueryResultDTO> listReportInitiativeSetting(ReportInitiativeSettingQueryParamDTO dto) {
        return QueryWrapperConverterPlus.of(reportInitiativeSettingMapper)
                .list(ReportInitiativeSettingQueryResultDTO.class, dto, sort());
    }

    /**
     * 查询列表：分页
     *
     * @param dto  查询条件
     * @param page 分页信息
     * @return 对象列表
     */
    public QueryPageResultDTO<ReportInitiativeSettingQueryResultDTO> pageReportInitiativeSetting(ReportInitiativeSettingQueryParamDTO dto, PageParamDTO page) {
        page.setSortFns(sort().getSortFns());
        return QueryWrapperConverterPlus.of(reportInitiativeSettingMapper)
                .page(ReportInitiativeSettingQueryResultDTO.class, dto, page);
    }

    private SortParamDTO sort() {
        return SortParamDTO.of(false, ReportInitiativeSetting::getSys)
                .and(false, ReportInitiativeSetting::getId);
    }

}

